<?php
class Galerie {
    public function uploadFile() {
        $url_path = $this->url_path;
        $filesize = $this->picture['size'];
        if ($filesize <= 2*1024*1024) {
            if ($this->picture['type'] != "" && ($this->picture['type'] == "image/pjpeg" || $this->picture['type'] == "image/jpeg")) {
                $this->picture['name'] = strtolower($this->picture['name']);
                ## Galerie-(Kategorie)-ordner installieren ##
                $source_file = $this->picture['tmp_name'];
                $destination_file = "gr_" . $this->picture['name'];
                $file = fopen($source_file, "r");
                if (move_uploaded_file($source_file, $url_path . "/galerie/" . $this->album_folder . "/" . $destination_file)) {
                    $random_pic_string = random_pic_string(20);
                    // Quelldatei
                    $from = $url_path . "/galerie/" . $this->album_folder . "/gr_" . $this->picture['name'];
                    // Ziel 1+2
                    $to1 = $url_path . "/galerie/" . $this->album_folder . "/thumbs/" . $this->picture['name'];
                    $to2 = $url_path . "/galerie/" . $this->album_folder . "/big/" . $this->picture['name'];
                        thumb($from, $to1, 100, 100, TRUE);
                    $info = getimagesize($url_path . "/galerie/" . $this->album_folder . "/gr_" . $this->picture['name']);
                    if ($info[0] <= $info[1])
                        thumb($from, $to2, 300, 300, TRUE);
                    else
                        thumb($from, $to2, 400, 400, TRUE);
                    watermark($url_path . "/galerie/" . $this->album_folder . "/big/" . $this->picture['name'], $url_path . "/images/galerie/watermark.png", $url_path . "/galerie/" . $this->album_folder . "/big/w_" . $this->picture['name'], 9);
                    @unlink($url_path . "/galerie/" . $this->album_folder . "/gr_" . $this->picture['name']);
                    @unlink($url_path . "/galerie/" . $this->album_folder . "/big/" . $this->picture['name']);
                    rename($url_path . "/galerie/" . $this->album_folder . "/thumbs/" . $this->picture['name'], $url_path . "/galerie/" . $this->album_folder . "/thumbs/" . $random_pic_string . "_" . $this->picture['name']);
                    rename($url_path . "/galerie/" . $this->album_folder . "/big/w_" . $this->picture['name'], $url_path . "/galerie/" . $this->album_folder . "/big/" . $random_pic_string . "_" . $this->picture['name']);
                    fclose($file);
                    return array(true);
                } else {
                    fclose($file);
                    return array(false, 'upload');
                }
            } else
                return array(false, 'imagetype');
        } else
            return array(false, 'filesize');
    }
}
?>